﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cesave.Infrastructure.CrossCutting.Logging;
using Cesave.Infrastructure.CrossCutting.IoC;
using Cesave.DistributedServices.Core.ErrorHandlers;
using System.ServiceModel;
using Cesave.Domain.PermisosModule.Contracts.Ejidos;

namespace Cesave.DistributedServices.PermisosModule
{
	public partial class PermisosModuleService
	{
		#region IPermisosModuleService Members

		/// <summary>
		/// 
		/// </summary>
		/// <param name="ejido"></param>
		public void AddEjido(Domain.PermisosModule.Entities.Ejido ejido)
		{
			try
			{
				IEjidoService ejidoService = IoCFactory.Resolve<IEjidoService>();
				ejidoService.AddEjido(ejido);
			}
			catch (Exception ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				ServiceError detail = ServiceError.Factory(ex.Message);
				throw new FaultException<ServiceError>(detail);
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="ejido"></param>
		public void ChangeEjido(Domain.PermisosModule.Entities.Ejido ejido)
		{
			try
			{
				IEjidoService ejidoService = IoCFactory.Resolve<IEjidoService>();
				ejidoService.ChangeEjido(ejido);
			}
			catch (Exception ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				ServiceError detail = ServiceError.Factory(ex.Message);
				throw new FaultException<ServiceError>(detail);
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="municipioGuid"></param>
		/// <returns></returns>
		public List<Domain.PermisosModule.Entities.Ejido> FindEjidosByMunicipio(Guid municipioGuid)
		{
			try
			{
				IEjidoService ejidoService = IoCFactory.Resolve<IEjidoService>();
				return ejidoService.FindEjidosByMunicipio(municipioGuid);
			}
			catch (Exception ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				ServiceError detail = ServiceError.Factory(ex.Message);
				throw new FaultException<ServiceError>(detail);
			}
		}

		#endregion
	}
}
